package com.msmall.community.bbs.action.wml;

import com.msmall.base.exception.AuthorityException;
import com.msmall.base.exception.DataNotFoundException;
import com.msmall.community.bbs.model.Topic;
import com.msmall.community.bbs.service.MasterManager;
import com.msmall.community.bbs.service.ThreadManager;
import com.msmall.community.bbs.service.TopicManager;

public class MasterAction extends BBSBaseAction {

	private static final long serialVersionUID = 3071801165639529764L;

	private Long moveBoardId; //移动帖子时，移动到的版区ID
	
	private String messageKey;
	
	private Topic topic;
	
	private MasterManager masterManager;
	
	private TopicManager topicManager;
	
	private ThreadManager threadManager;
	
	public String deleteTopic() throws AuthorityException{
		
		topicManager.delete(topicId, getUserid());
		
		String url = "";
		url = "boardIndex.do?boardId=" + boardId;
		setBbsToUrl(url);
		return SUCCESS;
	}
	
	public String deleteThread() throws AuthorityException, DataNotFoundException{
		threadManager.delete(threadId, getUserid());
		String url = "";
		url = "viewTopic.do?topicId=" + topicId;
		setBbsToUrl(url);
		return SUCCESS;
	}
	
	/**
	 * 置顶
	 * @return
	 * @throws DataNotFoundException
	 * @throws AuthorityException
	 */
	public String setTop() throws DataNotFoundException, AuthorityException{
		topicManager.setTop(topicId, getUserid());
		String url = "viewTopic.do?topicId=" + topicId;
		setBbsToUrl(url);
		setMessageKey("wml.bbs.master.topic.top.set");
		return SUCCESS;
	}
	/**
	 * 解除置顶
	 * @return
	 * @throws AuthorityException 
	 * @throws DataNotFoundException 
	 */
	public String deleteTop() throws DataNotFoundException, AuthorityException{
		topicManager.deleteTop(topicId, getUserid());
		String url = "viewTopic.do?topicId=" + topicId;
		setMessageKey("wml.bbs.master.topic.top.delete");
		setBbsToUrl(url);
		return SUCCESS;
	}
	/**
	 * 进入移动帖子页面
	 * @return
	 */
	public String toMove(){
		topic = (Topic) topicManager.get(Topic.class, topicId);
		return SUCCESS;
	}
	/**
	 * 移动帖子
	 * @return
	 */
	public String move(){
		masterManager.move(boardId, moveBoardId, topicId);
		String url = "viewTopic.do?topicId=" + topicId;
		setBbsToUrl(url);
		return SUCCESS;
	}
	public String setElite() throws DataNotFoundException, AuthorityException{
		topicManager.setElite(topicId, getUserid());
		String url = "viewTopic.do?topicId=" + topicId;
		setBbsToUrl(url);
		setMessageKey("wml.bbs.master.topic.elite.set");
		return SUCCESS;
	}
	/**
	 * 解除精华
	 * @return
	 * @throws AuthorityException 
	 * @throws DataNotFoundException 
	 */
	public String deleteElite() throws DataNotFoundException, AuthorityException{
		topicManager.deleteElite(topicId, getUserid());
		String url = "viewTopic.do?topicId=" + topicId;
		setBbsToUrl(url);
		setMessageKey("wml.bbs.master.topic.elite.delete");
		return SUCCESS;
	}
	public Long getMoveBoardId() {
		return moveBoardId;
	}

	public void setMoveBoardId(Long moveBoardId) {
		this.moveBoardId = moveBoardId;
	}

	public String getMessageKey() {
		return messageKey;
	}

	public void setMessageKey(String messageKey) {
		this.messageKey = messageKey;
	}

	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	public void setMasterManager(MasterManager masterManager) {
		this.masterManager = masterManager;
	}

	public void setTopicManager(TopicManager topicManager) {
		this.topicManager = topicManager;
	}

	public void setThreadManager(ThreadManager threadManager) {
		this.threadManager = threadManager;
	}
}
